﻿var statusId;

function makeAvailable() {
    var enable = true;
    var context = SP.ClientContext.get_current();
    var selection = SP.ListOperation.Selection.getSelectedItems(context);
    
    //Check if at minimum one is selected
    if (CountDictionary(selection) > 0)
        this.enable = true;
    else
        return false;
    //Check if a folder is selected
    var item;
    for (item in selection) {
        if (selection[item].fsObjType != 0)
            enable = false;
    }
    return enable;
}

function openDialog() {
    var ctx = SP.ClientContext.get_current();
    var items = SP.ListOperation.Selection.getSelectedItems(ctx);
    var list = SP.ListOperation.Selection.getSelectedList(ctx);
    var myItems = "";
    var k;
    for (k in items) {
        myItems += "|" + items[k].id;
    }

    var options = SP.UI.$create_DialogOptions();
//    options.width = winW;
//    options.height = winH - 20;
    options.url = '../../_layouts/moveitembetweenfolders/moveitem.aspx?items=' + myItems+'&listID='+list;
    options.dialogReturnValueCallback = Function.createDelegate(null, closeModal);
    SP.UI.ModalDialog.showModalDialog(options);
}

function closeModal(result, returnValue) {
    if (returnValue == '1') {
        this.statusId = SP.UI.Notify.addNotification(result, false);
        setTimeout('SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);', 1000);
    }
    else if(result == SP.UI.DialogResult.invalid) {
        this.statusId = SP.UI.Notify.addNotification(result, false);
    }
}
